package com.qf.controller;

import com.qf.Jifen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author MI
 * @ClassName JifenController.java
 * @createTime 2021年12月18日 22:38:00
 */
@RestController
@RequestMapping("/jifen")
public class JifenController {

    @PostMapping(value = "/save")
    public Map save(@RequestBody Jifen jifen) {
        System.out.println("调用积分保存接口");
        System.out.println(jifen);
        return new HashMap() {{
            put("isSuccess", true);
            put("msg", "save success");
        }};
    }

    @PostMapping(value = "/update")
    public Map update(@RequestBody Jifen jifen) {
        System.out.println(jifen);
        return new HashMap() {{
            put("isSuccess", true);
            put("msg", "update success");
        }};
    }

    @GetMapping(value = "/delete")
    public Map deletedById(Integer jifenId) {
        System.out.println("删除id为" + jifenId + "的积分信息");
        return new HashMap() {{
            put("isSuccess", true);
            put("msg", "deleted success");
        }};
    }

    @GetMapping(value = "/{jifenId}")
    public Jifen findJifenById(@PathVariable Integer jifenId) {
        System.out.println("已经查询到的" + jifenId + " 积分数据");
        return new Jifen(jifenId, 12, jifenId + "的积分");
    }

    @GetMapping(value = "/search")
    public Jifen search(Integer uid, String type) {
        System.out.println("uid" + uid + ":" + type);
        return new Jifen(uid, 12, type);
    }

    @PostMapping(value = "/searchByEntity")
    public List<Jifen> searchMap(@RequestBody Jifen jifen) {
        System.out.println("jifen");
        ArrayList<Jifen> jifens = new ArrayList<>();
        jifens.add(new Jifen(110, 12, "下单积分"));
        jifens.add(new Jifen(111, 18, "支付积分"));
        return jifens;
    }

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("b")
    public String b() {
        String object = restTemplate.getForObject("http://cloud-goods/goods/c", String.class);
        System.out.println("b");
        return object;
    }


}
